package com.zyj.myapplication.Activity;

import android.content.Context;
import android.content.Intent;
import android.media.Image;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zyj.myapplication.Javabean.ActivityInfo;
import com.zyj.myapplication.Model.ActivityModel;
import com.zyj.myapplication.R;

import it.sephiroth.android.library.picasso.Picasso;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class ActivityListActivity extends AppCompatActivity {
    private ImageView activityPhoto, btn_back;
    private TextView activityIntro, activitytime, activityplace, activityname, activityprice, activityrenshu;
    private LinearLayout activity_baoming;
    private String activity_id;
    private ActivityInfo activityinfo;
    private String Id, aduprice, stuprice;
    private Context mContext;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_activitylist);
        initViews();
        initEvents();
        initData();

    }

    private void initViews() {
        activityPhoto = (ImageView) findViewById(R.id.activityPhoto);
        activityIntro = (TextView) findViewById(R.id.activityIntro);
        activityprice = (TextView) findViewById(R.id.activity_price);
        activityplace = (TextView) findViewById(R.id.activity_place);
        activitytime = (TextView) findViewById(R.id.activity_time);
        activity_baoming = (LinearLayout) findViewById(R.id.activity_baoming);
        activityrenshu = (TextView) findViewById(R.id.activity_renshu);
        activityname = (TextView) findViewById(R.id.activity_name);
        btn_back = (ImageView) findViewById(R.id.btn_back);
    }

    private void initEvents() {
        activity_baoming.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent i = new Intent(ActivityListActivity.this, BaoMingActivity.class);
                i.putExtra("act_id", activityinfo.getId());
                i.putExtra("aduprice", activityinfo.getActivity_price());
                i.putExtra("stuprice", activityinfo.getActivity_price_stu());
                startActivity(i);
            }
        });
        btn_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initData() {
        Intent intent = getIntent();
        activity_id = intent.getStringExtra("activity_id");
        showData();
    }

    private void showData() {
        ActivityModel activityModel = new ActivityModel();
        Call<ActivityInfo> call = activityModel.getactivityinfo(activity_id);
        call.enqueue(new Callback<ActivityInfo>() {
            @Override
            public void onResponse(Call<ActivityInfo> call, Response<ActivityInfo> response) {
                activityinfo = response.body();
                activitytime.setText("活动时间：" + activityinfo.getUpdate_time());
                activityname.setText(/*"活动名称："+ */activityinfo.getActivity_name());
                activityIntro.setText("活动简介：" + activityinfo.getIntroduction());
                activityplace.setText("活动地址：" + activityinfo.getProvince_name() + "" + activityinfo.getCity_name() + "" + activityinfo.getPlace());
                activityprice.setText("活动费用：" + activityinfo.getActivity_price());
                activityrenshu.setText("已报名人数：" + activityinfo.getSign_num() + "人");

                String address = "http://172.24.10.175/workout/Uploads/" + activityinfo.getThumb();
                if (!activityinfo.getThumb().equals("")) {
                    Picasso.with(mContext).load(address).into(activityPhoto);
                }
            }

            /**/
            @Override
            public void onFailure(Call<ActivityInfo> call, Throwable t) {

            }
        });
    }
}
